﻿#region 命名空间

using System.ComponentModel.DataAnnotations.Schema;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;

#endregion

namespace Sharp.Domain.PlatformBoundedContext.ModelConfigurations
{
    public partial class UserGroupTypeConfiguration
        : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<UserGroup>
    {
        public UserGroupTypeConfiguration()
        {
            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            Property(t => t.Title)
                .HasMaxLength(50)
                .IsRequired();
            Property(t => t.Remark)
                .HasMaxLength(255)
                .IsOptional();
            Property(t => t.ParentId)
                .IsOptional();

            Property(t => t.CheckInTime)
                .IsRequired();
            Property(t => t.CheckInUserId)
                .IsRequired();
            Property(t => t.ModifiTime)
                .IsOptional();
            Property(t => t.ModifiedUserId)
                .IsOptional();

            HasMany(t => t.Users)
                .WithMany(t => t.UserGroups)
                .Map(m =>
                {
                    m.ToTable("Platform_UserUserGroups");
                    m.MapLeftKey("UserId");
                    m.MapRightKey("UserGroupId");
                });
        }
    }
}